package com.cry.todo.domain.project;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;

import com.cry.app.core.hibernate.MultiEntities;
import com.cry.todo.domain.User;

@Entity
@Table(name="todo_project_search")
public class ProjectSearch {
	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	private Integer id;
	private Integer number;
	private String nameOrDescription;

	@ManyToMany
	@JoinTable(name = "todo_project_search_users", 
			joinColumns = @JoinColumn(name = "project_search_id"), 
			inverseJoinColumns = @JoinColumn(name = "user_id"),
			uniqueConstraints = @UniqueConstraint(columnNames={"project_search_id","user_id"})
		)
	private List<User> users;

	@ManyToMany
	@JoinTable(name = "todo_project_search_categories", 
			joinColumns = @JoinColumn(name = "project_search_id"), 
			inverseJoinColumns = @JoinColumn(name = "category_id"),
			uniqueConstraints = @UniqueConstraint(columnNames={"project_search_id","category_id"})
		)
	private List<Category> categories;

	@ManyToMany
	@JoinTable(name = "todo_project_search_statuses", 
			joinColumns = @JoinColumn(name = "project_search_id"), 
			inverseJoinColumns = @JoinColumn(name = "status_id"),
			uniqueConstraints = @UniqueConstraint(columnNames={"project_search_id","status_id"})
		)
	private List<Status> statuses;

	@ManyToMany
	@JoinTable(name = "todo_project_search_supervisors", 
			joinColumns = @JoinColumn(name = "project_search_id"), 
			inverseJoinColumns = @JoinColumn(name = "user_id"),
			uniqueConstraints = @UniqueConstraint(columnNames={"project_search_id","user_id"})
		)
	private List<User> supervisors;

	@ManyToMany
	@JoinTable(name = "todo_project_search_creators", 
			joinColumns = @JoinColumn(name = "project_search_id"), 
			inverseJoinColumns = @JoinColumn(name = "user_id"),
			uniqueConstraints = @UniqueConstraint(columnNames={"project_search_id","user_id"})
		)
	private List<User> creators;
	
	
	private Date lastUpdateFrom;
	private Date lastUpdateTo;
	
	private Date createFrom;
	private Date createTo;
	
	public Integer getId() {
		return id;
	}
	public void setId(Integer id) {
		this.id = id;
	}
	public Integer getNumber() {
		return number;
	}
	public void setNumber(Integer number) {
		this.number = number;
	}
	public String getNameOrDescription() {
		return nameOrDescription;
	}
	public void setNameOrDescription(String nameOrDescription) {
		this.nameOrDescription = nameOrDescription;
	}
	
	public List<User> getUsers() {
		return users;
	}
	public void setUsers(List<User> users) {
		this.users = users;
	}
	public void setUsers(ArrayList<Integer> ids) throws Exception {
		setUsers(MultiEntities.getEntities(User.class, ids, getUsers())); 
	}

	public List<Category> getCategories() {
		return categories;
	}
	public void setCategories(List<Category> categories) {
		this.categories = categories;
	}
	public void setCategories(ArrayList<Integer> ids) throws Exception {
		setCategories(MultiEntities.getEntities(Category.class, ids, getCategories())); 
	}

	public List<Status> getStatuses() {
		return statuses;
	}
	public void setStatuses(List<Status> statuses) {
		this.statuses = statuses;
	}
	public void setStatuses(ArrayList<Integer> ids) throws Exception {
		setStatuses(MultiEntities.getEntities(Status.class, ids, getStatuses())); 
	}

	public List<User> getSupervisors() {
		return supervisors;
	}
	public void setSupervisors(List<User> supervisor) {
		this.supervisors = supervisor;
	}
	public void setSupervisors(ArrayList<Integer> ids) throws Exception {
		setSupervisors(MultiEntities.getEntities(User.class, ids, getSupervisors())); 
	}
	public Date getLastUpdateFrom() {
		return lastUpdateFrom;
	}
	public void setLastUpdateFrom(Date lastUpdateFrom) {
		this.lastUpdateFrom = lastUpdateFrom;
	}
	public Date getLastUpdateTo() {
		return lastUpdateTo;
	}
	public void setLastUpdateTo(Date lastUpdateTo) {
		this.lastUpdateTo = lastUpdateTo;
	}
	public Date getCreateFrom() {
		return createFrom;
	}
	public void setCreateFrom(Date createFrom) {
		this.createFrom = createFrom;
	}
	
	public void setCreateFrom(String createFrom) {
		//this.createFrom = createFrom;
		System.out.println(createFrom);
	}
	
	public Date getCreateTo() {
		return createTo;
	}
	public void setCreateTo(Date createTo) {
		this.createTo = createTo;
	}
	public List<User> getCreators() {
		return creators;
	}
	public void setCreators(List<User> creators) {
		this.creators = creators;
	}
	public void setCreators(ArrayList<Integer> ids) throws Exception {
		setCreators(MultiEntities.getEntities(User.class, ids, getCreators())); 
	}

	
}
